package core.controller.cmds;

import core.controller.CommandController;
import core.dal.AdminFunctionality;
import exceptions.UserNotFoundException;

public class UpdateUserCMD implements ICmd{

	AdminFunctionality functionality;
	final String level = "Admin";
	ICmd nextCMD;
	
	CommandController cc;
	
	public UpdateUserCMD(CommandController commandController, AdminFunctionality aF){
		this.cc = commandController;
		functionality = aF;
	}
	
	@Override
	public void setNextCmd(ICmd nextCmd) {
		nextCMD = nextCmd;
		
	}

	@Override
	public void execute(String cmd){
		if (cmd.contains("updateUser")) {
			


			
			
			try {
				cc.getTUI().showOutput("+Enter id of user: ");
				int id = Integer.parseInt(cc.getTUI().getInput());
				
				cc.getTUI().showOutput("Current name: " + functionality.showUser(id).getOprNavn()
						+ "\nEnter new name: ");
				String name = cc.getTUI().getInput();
				
				cc.getTUI().showOutput("Current pass: " + functionality.showUser(id).getPassword()
						+ "\nEnter new pass: ");
				String pass = cc.getTUI().getInput();
				
				cc.getTUI().showOutput("Current cpr: " + functionality.showUser(id).getCpr()
						+ "\nEnter new cpr: ");	
				String cpr = cc.getTUI().getInput();
				
				functionality.editUser(id, name, pass, cpr);
				
			} catch (UserNotFoundException e) {
				cc.getTUI().showOutput(e.getMessage());
				e.printStackTrace();
			}


		}

		if (nextCMD != null) {
			nextCMD.execute(cmd);
		}
	}

	@Override
	public String getInfo() {
		return "updateUser - Update a specific user";
		
	}

	@Override
	public String getLevel() {
		return this.level;
		
	}
}
